<?php

declare(strict_types=1);

namespace App\Box\Model;

use App\Lib\AdminEnum;
use Mine\MineModel;

/**
 * @property int $id ID
 * @property int $box_id 盒子id
 * @property int $product_id 产品id
 * @property string $product_name
 * @property string $img_url 产品图片
 * @property int $price 产品价格
 * @property int $max_price  最大价变物
 * @property int $probability 概率-展示给前台用的
 * @property int $weight 权重-后台计算用的
 * @property int $grade_id 道具等级
 * @property int $status 展示状态(1正常,2禁用)
 * @property int $created_by 创建者
 * @property int $create_time 创建时间
 * @property int $update_time 更新时间
 */
class BoxProduct extends MineModel
{
    const STATUS_YES = 1;
    const STATUS_NO = 0;

    protected ?string $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'box_product';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'box_id', 'product_id', 'product_name', 'img_url', 'price', 'max_price', 'probability', 'weight', 'grade_id', 'status', 'created_by', 'create_time', 'update_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'box_id' => 'integer', 'product_id' => 'integer', 'price' => 'integer', 'max_price' => 'integer', 'probability' => 'integer', 'weight' => 'integer', 'grade_id' => 'integer', 'status' => 'integer', 'created_by' => 'integer', 'create_time' => 'integer', 'update_time' => 'integer'];

    public function getPriceAttribute($value)
    {
        return number_format($value / AdminEnum::PRICE_MULTIPLE, 2, '.', '');
    }


    public function setPriceAttribute($value)
    {
        $this->attributes['price'] = (int)($value * AdminEnum::PRICE_MULTIPLE);
    }


}
